home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
TDE.ARJ
/
TDEDEMO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-14
|
8KB
|
265 lines
/***************************************************************************
FILENAME - TDEDEMO.CPP: Demonstration of TDataEntry objects.
----------------------
Class TDataEntry v1.0 - 07/14/92
--------------------------------
----------------------------------------------------------------------------
Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
----------------------------------------------------------------------------
A data entry class for Borland's Turbo Vision, derived from TInputLine.
Copyright Notice
================
As this material is ultimately derived from Borland source files, any of
their copyrights which MAY apply DO apply.
From the author's standpoint, you may use this material freely and,
hopefully, post any comments/corrections/enhancements to me at the above-
noted addresses. I do ask that you not distribute this material except as
originally received, including all source/documentation files in their
original form.
If you DO modify or enhance any of this code, please send any such changes
to me for incorporation into a future version. Any such enhancements will
be DONATED, without expectation of compensation or incorporation into
future versions. Again, if you distribute this code, please do so in its
original, unmodified form including all source files and documentation.
Source files included
=====================
TDE .DOC: This documentation.
TDE .MAN: How to use TDataEntry in your dialog objects
TDE .H : header file containing class declarations for classes
TDEFLAGS.H : " " " flags and command definitions
TDE .CPP: Class TDataEntry
TDEDATE .CPP: Class TDEDate
TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
TDENUMS .CPP: Class TDEInteger
TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
TDELIB .PRJ: Project for building library TDELIB.LIB
TDEDEMO .CPP: Demo program
TDEDEMO .PRJ: Project for building TDEDEMO.EXE
***************************************************************************/
#define Uses_TEventQueue
#define Uses_TEvent
#define Uses_TProgram
#define Uses_TApplication
#define Uses_TKeys
#define Uses_TRect
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
#define Uses_TStatusDef
#define Uses_TDeskTop
#define Uses_TView
#define Uses_TWindow
#define Uses_TFrame
#define Uses_TScroller
#define Uses_TScrollBar
#define Uses_TDialog
#define Uses_TButton
#define Uses_TSItem
#define Uses_TCheckBoxes
#define Uses_TRadioButtons
#define Uses_TLabel
#define Uses_TInputLine
#define Uses_TCollection
#define Uses_TStringCollection
#include <tv.h>
#define Uses_TDEDate
#define Uses_TDEZipCode
#define Uses_TDEPhone
#define Uses_TDEState
#define Uses_TDEButton
#include "tde.h"
const cmDemo = 200;
struct dlgRec
{
char name[31], add[31], city[31], state[3], zip[10], phn[11];
unsigned long dob;
} dlgData;
//--------------------------------------------------------------------------
// **** class TDemoDialog
//--------------------------------------------------------------------------
class TDemoDialog : public TDialog
{
public:
TDemoDialog();
virtual Boolean valid(ushort cmd);
};
//--------------------------------------------------------------------------
// **** TDemoDialog::TDemoDialog()
//--------------------------------------------------------------------------
TDemoDialog::TDemoDialog() :
TDialog(TRect(0,0,68,13), "TDataEntry Demo"),
TWindowInit(TDemoDialog::initFrame)
{
TView *v;
TDataEntry::globalID = 0; //* don't forget to set this
options |= ofCentered;
insert(new TStaticText(TRect(12,2,52,3),
"This dialog box uses TDataEntry Objects!"));
insert((v = new TDataEntry( 12, 4, 30)));
insert(new TLabel(TRect(5,4,11,5), "~N~ame:", v));
insert((v = new TDataEntry( 12, 5, 30)));
insert(new TLabel(TRect(2,5,11,6), "~A~ddress:", v));
insert((v = new TDataEntry( 12, 6, 30)));
insert(new TLabel(TRect(5,6,11,7), "~C~ity:", v));
insert((v = new TDEState( 12, 7, 2)));
((TDataEntry*)v)->localMode |= tdlAutoExit;
insert(new TLabel(TRect(4,7,11,8), "~S~tate:", v));
insert((v = new TDEZipCode( 32, 7, "~~~~~-~~~~")));
((TDataEntry*)v)->localMode |= tdlAutoExit;
insert(new TLabel(TRect(21,7,31,8), "~Z~ip Code:", v));
insert((v = new TDEPhone( 52, 4, "(~~~) ~~~-~~~~")));
((TDataEntry*)v)->localMode |= tdlAutoExit;
insert(new TLabel(TRect(44,4,51,5), "~P~hone:", v));
insert((v = new TDEDate( 52, 6, "~~/~~/~~")));
((TDataEntry*)v)->localMode |= (tdlAutoExit | tdlRequired);
insert(new TLabel(TRect(46,6,51,7), "~D~OB:", v));
insert(new TDEButton(TRect(12,10,25,12), "~O~k/Save", cmOK, bfDefault));
insert(new TDEButton(TRect(45,10,55,12), "Cancel", cmCancel, bfNormal));
selectNext(False);
}
//--------------------------------------------------------------------------
// **** TDemoDialog::valid()
// Hastily put together. Wouldn't cut it in real life but it gets the
// idea across.
//--------------------------------------------------------------------------
Boolean TDemoDialog::valid(ushort cmd)
{
Boolean isChanged = False;
switch( cmd )
{
case cmValid:
break;
case cmCancel:
case cmClose:
case cmQuit:
case cmOK:
if ( TDataEntry::queryChanged(this) )
isChanged = True;
if ( isChanged && cmd != cmOK )
{
cout << (char)7;
ushort r = messageBox("\003Data has changed! Save?",
mfWarning|mfYesNoCancel);
if ( r == cmNo )
return True;
else if ( r == cmCancel )
return False;
}
else if ( cmd != cmOK )
{
return True;
}
//* cmOK
if ( isChanged && TDataEntry::queryValid(this) )
return False;
//* save the stuff
return True;
default:
break;
}
return TDialog::valid(cmd);
}
//--------------------------------------------------------------------------
// **** class TDEApp
//--------------------------------------------------------------------------
class TDEApp : public TApplication
{
public:
TDEApp();
static TStatusLine *initStatusLine(TRect r);
virtual void handleEvent(TEvent& event);
};
//--------------------------------------------------------------------------
// **** TDEApp::TDEApp()
//--------------------------------------------------------------------------
TDEApp::TDEApp() : TProgInit( TDEApp::initStatusLine,
TDEApp::initMenuBar,
TDEApp::initDeskTop
)
{
//** Initialize TDataEntry's globalMode
TDataEntry::globalMode |= (tdgEnterIsTab|tdgUpDownEnable|tdgValidNow);
}
//--------------------------------------------------------------------------
// **** TDEApp::initStatusLine()
//--------------------------------------------------------------------------
TStatusLine *TDEApp::initStatusLine( TRect r )
{
r.a.y = r.b.y - 1;
return new TStatusLine( r,
*new TStatusDef(0, 0xFFFF) +
*new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
*new TStatusItem("~F4~ TDE Demo", kbF4, cmDemo)
);
}
//--------------------------------------------------------------------------
// **** TDEApp::handleEvent()
//--------------------------------------------------------------------------
void TDEApp::handleEvent(TEvent& event)
{
TApplication::handleEvent(event);
if( event.what == evCommand && event.message.command == cmDemo )
{
TDemoDialog *d = (TDemoDialog *)validView(new TDemoDialog());
if( d != 0 )
{
d->setData( &dlgData );
if ( deskTop->execView(d) == cmOK )
d->getData( &dlgData );
else
memset(&dlgData, '\0', sizeof(dlgData)); //* or something
destroy( d );
}
clearEvent(event);
}
}
//--------------------------------------------------------------------------
// **** MAIN ****
//--------------------------------------------------------------------------
int main()
{
TDEApp DemoApp;
DemoApp.run();
return 0;
}